package com.example.dense_rack_server.controller;


import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.dense_rack_server.entity.SysParamset;
import com.example.dense_rack_server.service.SysParamsetService;
import com.example.dense_rack_server.utils.ResponseModel;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * <p>
 * 系统参数 前端控制器
 * </p>
 *
 * @author  张彬 
 * @since 2025-03-21
 */
@Controller
@RequestMapping("/sys/paramset")
public class SysParamsetController {

    @Resource
    public SysParamsetService sysParamsetService;

    @GetMapping("/index")
    public ModelAndView list() {
        ModelAndView  modelAndView = new ModelAndView();
        modelAndView.setViewName("sysParamset/index");
        modelAndView.addObject("sysType", sysParamsetService.getOne(new QueryWrapper<SysParamset>().eq("id", 2)).getParamValue());
        return modelAndView;
    }

    @PostMapping("/systype/save")
    @ResponseBody
    public ResponseModel saveSystype(@RequestBody JSONObject data) {
        boolean success = sysParamsetService.update(new UpdateWrapper<SysParamset>().eq("id", 2).set("param_value", data.getStr("sysType")));
        return success ? ResponseModel.success("保存成功") : ResponseModel.fail("保存失败");
    }


}
